﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MVC.ApiExplorer.Demo
{
	public class MvcApplication : System.Web.HttpApplication
	{
		public static void RegisterGlobalFilters(GlobalFilterCollection filters)
		{
			filters.Add(new HandleErrorAttribute());
		}

		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			routes.MapRoute(
				"ApiExplorer",
				"ActionExplore/Explore",
				new { controller = "ActionExplore", action = "Explore" },
				new[] { "MVC.ApiExplorer" }
			);

			routes.MapRoute(
				"Default_API", // Route name
				"api/{action}", // URL with parameters
				new { controller = "API", action = "Index"}, // Parameter defaults
				new[] { "The.controller.you.want.to.explore" }
			);

			routes.MapRoute(
				"Default_Complex_Model_API", // Route name
				"complex_model_api/{action}", // URL with parameters
				new { controller = "ComplexModelAPI", action = "Index" }, // Parameter defaults
				new[] { "The.controller.you.want.to.explore" }
			);

			routes.MapRoute(
				"Default_Enumerable_API", // Route name
				"enumerable_api/{action}", // URL with parameters
				new { controller = "EnumerableAPI", action = "Index" }, // Parameter defaults
				new[] { "The.controller.you.want.to.explore" }
			);

			routes.MapRoute(
				"Default", // Route name
				"{action}/{id}", // URL with parameters
				new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
				new[] { "The.controller.you.want.to.explore" }
			);

		}

		protected void Application_Start()
		{
			AreaRegistration.RegisterAllAreas();

			RegisterGlobalFilters(GlobalFilters.Filters);
			RegisterRoutes(RouteTable.Routes);
		}
	}
}